﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MySql.Data.MySqlClient;

namespace MySQLLib
{
    public class Character_tickets
    {
        string[,] _character_tickets;
        private MySqlConnection conn;

        public void refresh()
        {
            string[] columns = new string[1];
            columns[0] = "*";

            this._character_tickets = Query.SelectQuery(this.conn, "character_tickets", columns);
        }

        public void setConnection(MySqlConnection connection)
        {
            this.conn = connection;
        }

        public string[,] Tickets
        {
            get { return this._character_tickets; }
        }

        public string[] getTicketInfo(int ticketid, bool refresh = false)
        {
            if (refresh)
                this.refresh();

            string[] ticket = new string[_character_tickets.GetLength(1)];
            for (int i = 0; i < ticket.Length; i++)
            {
                ticket[i] = this._character_tickets[ticketid - 1, i];
            }
            return ticket;
        }

        public void deleteTicket(int id)
        {
            Query.DeleteQuery(this.conn, "character_tickets", "id=" + id);
        }

        public void addTicket(int owner, int item_id, int start_time, int end_time, int active)
        {
            string[] columns = new string[5];
            columns[0] = "owner";
            columns[1] = "item_id";
            columns[2] = "start_time";
            columns[3] = "end_time";
            columns[4] = "active";

            string[] values = new string[5];
            values[0] = owner.ToString();
            values[1] = item_id.ToString();
            values[2] = start_time.ToString();
            values[3] = end_time.ToString();
            values[4] = active.ToString();

            Query.InsertQuery(this.conn, "character_tickets", columns, values);
        }
    }
}
